package leetcode.editor.cn;

public class _240_SearchA2dMatrixIi {
    public static void main(String[] args) {
        Solution solution = new _240_SearchA2dMatrixIi().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public boolean searchMatrix(int[][] matrix, int target) {
            int m = matrix.length, n = matrix[0].length;
            int row = 0, col = n - 1;
            while (row < m && col >= 0) {
                int num = matrix[row][col];
                if (num == target) {
                    return true;
                } else if (num > target) {
                    col--;
                } else if (num < target) {
                    row++;
                }
            }
            return false;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}